package com.yoomiito.app.ui.my.remain.detail

import com.yoomiito.app.base.AppConfig
import com.yoomiito.app.base.BaseActPresenter
import com.yoomiito.app.model.my.MyMoneyDetailInfo
import com.yoomiito.app.net.YmApi
import com.yoomiito.app.utils.NetworkUtils
import com.yoomiito.app.utils.YMToast

import cn.droidlover.xdroidmvp.net.ApiException
import cn.droidlover.xdroidmvp.net.ApiSubscriber
import cn.droidlover.xdroidmvp.net.XApi

class MyMoneyDetailPresenter(appConfig: AppConfig) :
    BaseActPresenter<MyMoneyDetailActivity>(appConfig) {

    fun getMoneyDetailData(page: Int,type:Int) {
        YmApi.getYmService()
            .getMyMoneyDetail(page,type)
            .compose(v.bindToLifecycle())
            .compose(XApi.getApiTransformerData())
            .compose(XApi.getScheduler())
            .subscribe(object : ApiSubscriber<MyMoneyDetailInfo>() {
                override fun onSuccess(bean: MyMoneyDetailInfo) {
                    v.setMoneyDetailData(bean)
                }

                override fun onFail(error: ApiException) {
                    YMToast.showText("get data error")
                }
            })
    }

    //区县代理明细
    fun getMoneyDetailDataAgent(page: Int) {
        YmApi.getYmService()
            .getMyMoneyDetailAgent(page)
            .compose(v.bindToLifecycle())
            .compose(XApi.getApiTransformerData())
            .compose(XApi.getScheduler())
            .subscribe(object : ApiSubscriber<MyMoneyDetailInfo>() {
                override fun onSuccess(bean: MyMoneyDetailInfo) {
                    v.setMoneyDetailData(bean)
                }

                override fun onFail(error: ApiException) {
                    YMToast.showText("get data error")
                }
            })
    }

    fun getYouMiDetail(page: Int) {
        YmApi.getYmService()
            .getYouMiDetailList(page)
            .compose(v.bindToLifecycle())
            .compose(XApi.getApiTransformerData())
            .compose(XApi.getScheduler())
            .subscribe(object : ApiSubscriber<MyMoneyDetailInfo>(handleException()) {

                override fun onSuccess(bean: MyMoneyDetailInfo) {
                    v.setMoneyDetailData(bean)
                }

                override fun onFail(error: ApiException) {
                    v.dismissLoading()
                }
            })
    }

    fun withdrawDetail(position: Int, id: String, bizType: Int) {
        YmApi.getYmService()
            .withdrawDetail(id, bizType)
            .compose(v.bindToLifecycle())
            .compose(XApi.getApiTransformerData())
            .compose(XApi.getScheduler())
            .subscribe(object : ApiSubscriber<MyMoneyDetailInfo.DataBean>(handleException()) {

                override fun onSuccess(bean: MyMoneyDetailInfo.DataBean) {
                    v.setMoneyDetail(position, bean)
                }

                override fun onFail(error: ApiException) {
                    v.dismissLoading()
                }
            })
    }


    fun starStoreCoinDetail(page: Int) {
        YmApi.getYmService()
            .starStoreCoinDetail(page, 20)
            .compose(v.bindToLifecycle())
            .compose(XApi.getApiTransformerData())
            .compose(XApi.getScheduler())
            .subscribe(object : ApiSubscriber<MyMoneyDetailInfo>(handleException()) {

                override fun onSuccess(bean: MyMoneyDetailInfo) {
                    v.setMoneyDetailData(bean)
                }

                override fun onFail(error: ApiException) {
                    v.dismissLoading()
                }
            })

    }


}
